const express = require("express");
const router = express.Router();
const { conMysql } = require("../db");

//根据uid修改业务员信息
router.post("/updateSalesperson", (req, res) => {
    let { uid, uname, uphone, uphoto, enterprises, position } = req.body;
    //判断是否为空
    if (!uid || !uname || !uphone || !uphoto || !enterprises || !position) {
        res.output("修改失败", 1001, null);
        return;
    }
    //根据uid查询业务员是否存在
    const sql1 = `select * from db_salesperson where uid='${uid}'`;

    conMysql(sql1).then((result) => {
        if (result.length == 0) {
            res.output("业务员不存在", 1001, null);
            return;
        }
        //修改业务员信息
        const sql = `update db_salesperson set uname='${uname}',uphone='${uphone}',uphoto='${uphoto}',enterprises='${enterprises}',position='${position}' where uid='${uid}'`;
        conMysql(sql)
            .then((result) => {
                res.output("修改成功", 0, null);
            })
            .catch((err) => {
                //业务员不存在
                res.output("修改失败、业务员不存在", 500, null);
            });
    }).catch((err) => {
        res.output(err, 500, null);
    })



})
module.exports = router;